package haierhome.krund.cn.daggertworetrofitrxjavamvp.rxjava.rxbinding;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;

import com.jakewharton.rxbinding2.view.RxView;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import haierhome.krund.cn.daggertworetrofitrxjavamvp.R;

public class RxbindingActivity extends AppCompatActivity {

    @BindView(R.id.bt_login)
    Button btLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rxbinding);
        ButterKnife.bind(this);

        initView();
        initListener();

    }

    private void initListener() {
//        RxView.clicks(btLogin).subscribe(new Consumer<Object>() {
//            @Override
//            public void accept(Object o) throws Exception {
//                Log.i("@@", "你点击了按钮");
//            }
//        });
        RxView.clicks(btLogin).
                //2秒内防点击
                throttleFirst(2, TimeUnit.SECONDS).
                subscribe((t) -> Log.i("@@", "你点击了按钮"));
    }

    private void initView() {
        ButterKnife.bind(this);
    }
}
